#pragma once
#include <iostream>
#include <memory>
#include "Protocol.hpp"
class NetCal
{
public:
    std::shared_ptr<Response> calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuildResponseDefault();
        switch (req->get_oper())
        {
        case '+':
            resp->set_result(req->get_x() + req->get_y());
            break;
        case '-':
            resp->set_result(req->get_x() - req->get_y());
            break;
        case '*':
            resp->set_result(req->get_x() * req->get_y());
            break;
        case '/':
            if (req->get_y() == 0)
            {
                resp->set_code(1);
                resp->set_desc("Div zero!");
            }
            else
            {
                resp->set_result(req->get_x() / req->get_y());
            }
            break;
            default:
             resp->set_code(2);
            resp->set_desc("illegal operation");
            break;
        }
        return resp;
    }
};
